package org.taobao.ibatiside.ui.view;

import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;

public class OpenActionProvider extends CommonActionProvider {

	private OpenIbatisFileAction action;
	private ISelectionProvider selectionProvider;
	public OpenActionProvider() {
	}
	OpenIbatisFileAction getAction(){
		return action;
	}
	@Override
	public void init(ICommonActionExtensionSite aSite) {
		super.init(aSite);
		this.selectionProvider = aSite.getViewSite().getSelectionProvider();
		this.action = new OpenIbatisFileAction();
		this.action.initialize((CommonViewer) aSite.getStructuredViewer());
	}
	@Override
	public void fillActionBars(IActionBars actionBars) {
		if (getContext().getSelection().isEmpty() || ((IStructuredSelection)getContext().getSelection()).getFirstElement() == null)
		{
			return;
		}
		getAction().selectionChanged(new SelectionChangedEvent(this.selectionProvider, this.getContext().getSelection()));
		actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, action);
	}
}
